#include<stdio.h>
#include<stdlib.h>
struct MyStruct
{
	char ID[15];
	int testNum;
	int examNum;
};
int main() {
	int N, M;
	scanf("%d\n", &N);
	MyStruct *p=(MyStruct*)malloc(N * sizeof(MyStruct));
	for (int i = 0; i < N; i++)
	{
		scanf("%s%d%d", p[i].ID, &p[i].testNum, &p[i].examNum);
	}
	scanf("%d\n", &M);
	int *intp = (int*)malloc(M * sizeof(int));
	for (int i = 0; i < M; i++)
	{
		scanf("%d", &intp[i]);
	}
	for (int j = 0; j < M; j++)
	{
		for (int i = 0; i < N; i++)
		{
			if (p[i].testNum == intp[j]) {
				printf("%s %d\n", p[i].ID, p[i].examNum);
			}
		}
	}


	
	
	
	return 0;
}